﻿#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickView>
#include <QQmlComponent>

#include "global/xnamespace.h"
#include "config/Config.h"
#include "model/RosterModel.h"
#include "multimedia/AudioPlayer.h"
#include "qmlobjectregister.h"
#include "ApplicationEngine.h"
#include "util/PhotoUtil.h"

X_NAMESPACE

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.setApplicationVersion(APP_VERSION);
    app.setOrganizationName(APP_ORG);
    app.setApplicationName(APP_NAME);

    QmlObjectRegister::registerEnums();
    QmlObjectRegister::registerUtils();
    QmlObjectRegister::registerSubModelTypes();
    QmlObjectRegister::registerTopLevelModelSingleton();

    // 初始化配置
    Config::instance();

    if(argc > 1) {
        QQmlApplicationEngine engine;
        engine.load(QUrl(argv[1]));
        return app.exec();
    } else {
        // 注册engine全局变量
        ApplicationEngine engine(NULL);
        app.setProperty("engine", QVariant::fromValue(&engine));

        engine.run();
        return app.exec();
    }
}
